package com.acme.bankapp.service.bank;

import java.util.List;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;

public class BankService {
	public static void addClient(Bank bank, Client client) {
		bank.addClient(client);
	}
	
	public static void printMaximumAmountToWithdraw(Bank bank) {
		List<Client> clients = bank.getClients();
		for (Client client : clients) {
			System.out.printf("%s:\t%.2f%n",
					client.getClientSalutation(),
					client.getAccount().getMaximumAmountToWithdraw());
		}
	}
	
	public static void setupClientRegistrationListeners(Bank bank) {
		// PrintClientListener
		bank.addClientRegistrationListener(new ClientRegistrationListener() {
			public void onClientAdded(Client c) {
				System.out.println(c);
			}
		});
		
		// EmailNotificationListener
		bank.addClientRegistrationListener(new ClientRegistrationListener() {
			public void onClientAdded(Client c) {
				System.out.printf("Notification email for client %s to be sent%n",
						c.getClientSalutation());
			}
		});
		
		bank.addClientRegistrationListener(new DebugListener());
	}
	
	private static class DebugListener implements ClientRegistrationListener {
		public void onClientAdded(Client client) {
			System.out.printf("Client: %s; Time: %2$tF %2$tT%n",
					client.getClientSalutation(),
					new java.util.Date());
		}
	}
}
